<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<div>
			<input type="text" id="inputName" />
			<div id="selectContainer" class="selectContainer">
				
			</div>
		</div>
		
		
		
		
		<script type="text/javascript">
			/* 获取的对象数组数据 */
			var obj = [{"index":"1","name":"中原银行"},
						{"index":"2","name":"郑州银行"},
						{"index":"3","name":"中国银行"},
						{"index":"4","name":"中兴银行"},
						{"index":"5","name":"晋中银行"}];
			
			var obj_inputName = document.getElementById("inputName");
			var selectContainer = document.getElementById("selectContainer");
			var str;
			var searchCache = {};
			var arrCache = [];
			obj_inputName.addEventListener("change",searchFor);
			// obj_inputName.addEventListener("input",searchFor);
			function searchFor(){
				str = obj_inputName.value;
				if(str==""){
					selectContainer.innerHTML = "";
					return "输入内容为空";
				}
				if(str in searchCache){
					console.log(str in searchCache);
					for(var index in searchCache[str]){
						selectContainer.innerHTML = selectContainer.innerHTML + ('<div class="eachList" id="bankName'+ index +'" >'+ searchCache[str][index] +'</div>')
					}
					return;
				}
				for(var i in obj){
					console.log(i);
					if(obj[i]["name"].indexOf(str)>=0){
						/* 方法一 */
							arrCache.push(obj[i]["name"]);
							selectContainer.innerHTML = selectContainer.innerHTML + ('<div class="eachList" id="bankName'+ obj[i]["index"] +'" >'+ obj[i]["name"] +'</div>')
						
						/* 方法二 */
							
					}
				}
				console.log(arrCache);
				searchCache[str] = arrCache;
				arrCache = [];
				console.log(searchCache);
			};
			
			
		</script>
	</body>
</html>